<?php 
require("../db/opendb.php");

//echo "reco_recvr_id=";
//echo $_POST['ID'];
//echo "<br>";

$from_email = $_GET['from_email'];
$from_fname = $_GET['from_fname'];
$from_lname = $_GET['from_lname'];
$recommendation = $_GET['recoresponse'];
$for_username = $_GET['for_username'];
$for_userid = $_GET['for_userid'];

$esql = "Select ID, Username, First_Name, Last_Name, Email from Users  where Email = '".$from_email."'";
$eresult = mysql_query($esql) or die ("SQL Error".mysql_error());


$erow = mysql_fetch_assoc($eresult);

if($erow == '')
{
echo "No user found";
$verified = 1;

$insertquery = "insert into Users(";
$insertquery .= "Username,";
$insertquery .= "Password,";
$insertquery .= "First_Name,";
$insertquery .= "Last_Name,";
$insertquery .= "Phone,";
$insertquery .= "Date_Created,";
$insertquery .= "Verified,";
$insertquery .= "Email)";
//$insertquery .= "Street,";
//$insertquery .= "City,";
//$insertquery .= "State,";
//$insertquery .= "Zip)";
$insertquery .= "Values(";
$insertquery .= "'".$from_email."',";
$insertquery .= "'".$firstname."',";
$insertquery .= "'".$firstname."',";
$insertquery .= "'".$lastname."',";
$insertquery .= "'".$phone."',";
$insertquery .= "'".date("Y-m-d")."',";
$insertquery .= "'".$verified."',";
$insertquery .= "'".$from_email."')";


mysql_query($insertquery) or die(mysql_error());
$new_id = mysql_insert_id();

}
else
{

$new_id = $erow['ID'];

}

echo "sql = ".$esql."<br>";
echo "eresult = ".$eresult;
print_r($eresult);
echo "<br>";
echo "erow =  ";
print_r($erow);
echo "<br>";


//$sql = "Select r.Message, r.ID as r_id, u.Username, u.First_Name, u.ID as user_id, u.Last_Name from Recommend_Request r left join Users u on u.ID = r.Owner where r.Recommender = '".$_SESSION['id']."' and r.Status = '0' and r.ID = '".$_POST['user_id']."'";
//$result = mysql_query($sql) or die ("SQL Error".mysql_error());
//$row = mysql_fetch_assoc($result);
//
//$insertquery = "update Recommend_Request set Status = 1 where ID = '".$row['r_id']."'";
//mysql_query($insertquery) or die ("SQL Error".mysql_error());
//
$insertquery = "insert into Recommendations(Owner, Other_User, Message, Date_Created) VALUES ('".$new_id."','".$for_userid."','".$recommendation."','".date('Y-m-d H-i-s')."')";

echo "reco_query = ".$insertquery."<br>";

//mysql_query($insertquery) or die ("SQL Error".mysql_error());
//$insert_id = mysql_insert_id();




?>
<?php require("../db/closedb.php");?>